// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    status:0,//按钮状态切换功能
    total: 0,//总体评价
    servingSpseed: 0,//上菜速度S
    foodTasftes: 0,//菜品口味
    ambiance: 0,//用餐环境
  },
  //添加评论
  addComment:function(event){
    this.setData({
      comment:event.detail.value
    })
    // console.log(this.data.comment)
  },
  // 事件处理函数
  img_bind: function(event) {
    var id = event.currentTarget.dataset.item + 1;
    var variable = event.currentTarget.dataset.name;
    console.log(id)
    console.log(variable)
    if (variable == "total")
    this.setData({
      total: id,
    })
    else if (variable == "servingSpseed")
      this.setData({
        servingSpseed: id,
      })
    else if (variable == "foodTasftes")
      this.setData({
        foodTasftes: id,
      })
    else
    {
      this.setData({
        ambiance: id,
      })
    }
  },
  result:function(){
    console.log(this.data.comment)
   let total=this.data.total
   let servingSpseed=this.data.servingSpseed
   let foodTasftes=this.data.foodTasftes
   let ambiance=this.data.ambiance
   let comment=this.data.comment
   console.log(comment)
   if(total==0 || servingSpseed==0 || foodTasftes==0 || ambiance==0 || comment==""){
       wx.showToast({
         title: '请点评完和评论完',
         icon: 'success',
         duration: 500
       })
   }
   else{
    wx.request({
      url: 'https://999.tianba.work/api/comment/add',
      data:{
       order_id:this.options.order_id,
       total:total,
       comment:comment,
       servingSpseed:servingSpseed,
       foodTasftes:foodTasftes,
       ambiance:ambiance,
      },
      success(res){
        console.log(res)
        wx.switchTab({
         url: '/pages/list/list',   
         success(){
            let page=getCurrentPages().pop();
            if(page ==undefined ||page ==null) return;
            page.list();
         }
       })
       setTimeout(() => {
        wx.showToast({
          title: '评价成功',
          icon: 'success',
          duration: 500
        })
      }, 500); 
      }
    })
   }
  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('该订单id',options.order_id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})
